package com.xxx.modules.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxx.modules.mapper.NewsMapper;
import com.xxx.modules.entity.News;
import com.xxx.modules.service.NewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.Arrays;
import com.xxx.modules.utils.TimeUtil;

/**
 * news
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2023-02-11
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {

    @Autowired
    private NewsMapper newsMapper;


    @Override
    public PageInfo<News> selectNewsInfo(News news, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<News> wrapper = new QueryWrapper<>();
        List<News> data = newsMapper.selectListInfo(news);
        return new PageInfo<>(data);
    }

    @Override
    public void saveNewsInfo(News news) {
        news.setCreateTime(TimeUtil.getCurrentTime());
        newsMapper.insert(news);
    }

    @Override
    public void updateNewsInfo(News news) {
        newsMapper.updateById(news);
    }

    @Override
    public void delNewsInfo(Integer id) {
        newsMapper.deleteById(id);
    }

    @Override
    public void delBatchNewsInfo(String idList) {
        List<String> list = Arrays.asList(idList.split(","));
        newsMapper.deleteBatchIds(list);
    }


}